//
// Created by 0209 on 2025/10/28.
//

#ifndef UDPCLIENT_H
#define UDPCLIENT_H

#pragma once
#include <QObject>
#include <QUdpSocket>
#include <QHostAddress>

/*
 * UDP
 */

class UdpBackendClient : public QObject {
    Q_OBJECT
public:
    explicit UdpBackendClient(QObject *parent = nullptr);
    ~UdpBackendClient();

    bool Udp_Init(quint16 localPort);//初始化UDP并且保定本地端口
    void Udp_Close();
    void Udp_sendData(const QByteArray &data, const QString &remoteIp, quint16 remotePort);// 发送数据到指定地址和端口
    bool Udp_IsOpen() const;    // 判断UDP是否已打开
    QString Udp_ErrorString() const;

private:
    QUdpSocket *udpSocket = nullptr;
    quint16 boundPort = 0;  //本地的端口
    bool isOpen = false;    // 记录UDP是否已打开
};



#endif //UDPCLIENT_H
